home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / drvspace / drvspace.frm < prev    next >
Text File  |  1996-12-31  |  2KB  |  92 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Space"
  4.    ClientHeight    =   1545
  5.    ClientLeft      =   3045
  6.    ClientTop       =   2820
  7.    ClientWidth     =   1965
  8.    Height          =   1950
  9.    Left            =   2985
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1545
  12.    ScaleWidth      =   1965
  13.    Top             =   2475
  14.    Width           =   2085
  15.    Begin VB.CommandButton Command1 
  16.       Caption         =   "Get Space"
  17.       Height          =   375
  18.       Left            =   360
  19.       TabIndex        =   3
  20.       Top             =   1080
  21.       Width           =   1215
  22.    End
  23.    Begin VB.TextBox Text1 
  24.       Height          =   285
  25.       Left            =   1560
  26.       TabIndex        =   1
  27.       Top             =   120
  28.       Width           =   255
  29.    End
  30.    Begin VB.Label Label2 
  31.       Caption         =   "Enter Drive Letter"
  32.       Height          =   255
  33.       Left            =   120
  34.       TabIndex        =   2
  35.       Top             =   120
  36.       Width           =   1335
  37.    End
  38.    Begin VB.Label Label1 
  39.       Alignment       =   2  'Center
  40.       Height          =   255
  41.       Left            =   0
  42.       TabIndex        =   0
  43.       Top             =   600
  44.       Width           =   1935
  45.    End
  46. End
  47. Attribute VB_Name = "Form1"
  48. Attribute VB_Creatable = False
  49. Attribute VB_Exposed = False
  50. Option Explicit
  51.  
  52.  
  53.  
  54. Public Function DiskSpace(DrivePath As String) As Double
  55. ' Pass the function the drive letter to get the free space of
  56.   Dim Drive As String
  57.   Dim SectorsPerCluster As Long, BytesPerSector As Long
  58.   Dim NumberOfFreeClusters As Long, TotalClusters As Long, Sts As Long
  59.   Dim DS
  60.  
  61.   Drive = Left(Trim(DrivePath), 1) & ":\"     ' Ensure path is at the root.
  62.   Sts = GetDiskFreeSpace(Drive, SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalClusters)
  63.   If Sts <> 0 Then
  64.     DiskSpace = SectorsPerCluster * BytesPerSector * NumberOfFreeClusters
  65.     DS = Format$(DiskSpace, "###,###")
  66.     Label1 = DS & " bytes"
  67.   Else
  68.     DiskSpace = -1        ' Should Call GetLastError here but -1 will do for example
  69.   End If
  70. End Function
  71.  
  72. Private Sub Command1_Click()
  73.  
  74. Dim x
  75.  
  76. If Text1 = "" Then
  77.     MsgBox "Try typing a drive letter. It works better!"
  78. Else
  79.     x = DiskSpace(Text1.Text)
  80.     Text1.SetFocus
  81. End If
  82.  
  83. End Sub
  84.  
  85.  
  86. Private Sub Form_Load()
  87.     Show
  88.     Text1.SetFocus
  89. End Sub
  90.  
  91.  
  92.